home *** CD-ROM | disk | FTP | other *** search
- /*
- file PackageUtils.c
-
- Description:
- This file contains the package utility function IdentifyPackage that
- package savy applications can use for identifying document packages.
-
- PackageTool is an application illustrating how to create application
- packages in Mac OS 9. It provides a simple interface for converting
- correctly formatted folders into packages and vice versa.
-
- by John Montbriand, 1999.
-
- Copyright: © 1999 by Apple Computer, Inc.
- all rights reserved.
-
- Disclaimer:
- You may incorporate this sample code into your applications without
- restriction, though the sample code has been provided "AS IS" and the
- responsibility for its operation is 100% yours. However, what you are
- not permitted to do is to redistribute the source as "DSC Sample Code"
- after having made changes. If you're going to re-distribute the source,
- we require that you make it clear in the source that the code was
- descended from Apple Sample Code, but that you've made changes.
-
- Change History (most recent first):
- 10/19/99 created by John Montbriand
- */
-
- #include "PackageUtils.h"
- #include <Aliases.h>
-
- /* IdentifyPackage returns true if the file system object refered to
- by *target refers to a package. If it is a package, then
- *mainPackageFile is set to refer to the package's main file. */
- Boolean IdentifyPackage(FSSpec *target, FSSpec *mainPackageFile) {
- CInfoPBRec cat;
- OSErr err;
- long packageFolderDirID;
- Str255 name;
- FSSpec aliasFile;
- Boolean targetIsFolder, wasAliased;
- /* check the target's flags */
- cat.dirInfo.ioNamePtr = target->name;
- cat.dirInfo.ioVRefNum = target->vRefNum;
- cat.dirInfo.ioFDirIndex = 0;
- cat.dirInfo.ioDrDirID = target->parID;
- err = PBGetCatInfoSync(&cat);
- if (err != noErr) return false;
- if (((cat.dirInfo.ioFlAttrib & 16) != 0) && ((cat.dirInfo.ioDrUsrWds.frFlags & kHasBundle) != 0)) {
- /* search for a top level alias file */
- packageFolderDirID = cat.dirInfo.ioDrDirID;
- cat.dirInfo.ioNamePtr = name;
- cat.dirInfo.ioVRefNum = target->vRefNum;
- cat.dirInfo.ioFDirIndex = 1;
- cat.dirInfo.ioDrDirID = packageFolderDirID;
- /* find the first alias file in the directory */
- while (PBGetCatInfoSync(&cat) == noErr) {
- if (((cat.dirInfo.ioFlAttrib & 16) == 0) && ((cat.dirInfo.ioDrUsrWds.frFlags & kIsAlias) != 0)) {
- err = FSMakeFSSpec(target->vRefNum, packageFolderDirID, name, &aliasFile);
- if (err != noErr) return false;
- err = ResolveAliasFile(&aliasFile, false, &targetIsFolder, &wasAliased);
- if (err != noErr) return false;
- if (mainPackageFile != NULL)
- *mainPackageFile = aliasFile;
- return true;
- }
- cat.dirInfo.ioFDirIndex++;
- cat.dirInfo.ioDrDirID = packageFolderDirID;
- }
- }
- /* no matching files found */
- return false;
- }
-
-